package com.algorithm.queue;/*
 *@Author:DOWN
 *@Date:2021/12/15 15:45
 *@Comment:
 */

import com.algorithm.arrays.Arrays;

public class ArrayQueue <E> implements QueueInterface<E> {
    private Arrays<E> data;
    public ArrayQueue(int capacity) {
        data = new Arrays<>(capacity);
    }

    public ArrayQueue() {
        data = new Arrays<>();
    }
    @Override
    public int getSize() {
        return this.data.getSize();
    }

    @Override
    public boolean isEmpty() {
        return this.data.isEmpty();
    }

    @Override
    public void enqueue(E e) {
        this.data.add(e);
    }

    @Override
    public E dequeue() {
        return data.removeFirst();
    }

    @Override
    public E getFront() {
        return data.getFist();
    }
    @Override
    public String toString() {
        if (this.data == null) {
            return "null";
        }
        int iMax = this.data.getSize() - 1;
        if (iMax == -1) {
            return "[]";
        }
        StringBuilder b = new StringBuilder();
        b.append("Queue-Front:");
        b.append('[');
        for (int i = 0; i < this.data.getSize(); i++) {
            b.append(this.data.get(i));
            if (i == iMax) {
                return b.append(']').toString();
            }
            b.append(", ");
        }
        return b.toString();
    }

}
